import java.util.Arrays;
import java.util.Random;

public class Test {
    public static void testInsertSort(int[] array1) {
        array1 = Arrays.copyOf(array1, array1.length);
        long start = System.currentTimeMillis();
        TestSort.insertSort(array1);
        long end = System.currentTimeMillis();
        System.out.println("直接插入排序耗时：" + (end - start));
    }

    public static void testShelltSort(int[] array2) {
        array2 = Arrays.copyOf(array2, array2.length);
        long start = System.currentTimeMillis();
        TestSort.shellSort(array2);
        long end = System.currentTimeMillis();
        System.out.println("希尔排序耗时：" + (end - start));
    }

    public static void testselectSort(int[] array2) {
        array2 = Arrays.copyOf(array2, array2.length);
        long start = System.currentTimeMillis();
        TestSort.selectSort(array2);
        long end = System.currentTimeMillis();
        System.out.println("选择排序耗时：" + (end - start));
    }

    public static void testquicktSort(int[] array) {
        array = Arrays.copyOf(array, array.length);
        long start = System.currentTimeMillis();
        TestSort.quickSort(array);
        long end = System.currentTimeMillis();
        System.out.println("快速排序耗时：" + (end - start));
    }

    //给数组赋有序的数值
    public static void inItOrder(int[] array) {
        for (int i = 0; i < array.length; i++) {
            //array[i] = array.length - i;//赋值为逆序
            array[i] = i;
        }
    }

    //给数组赋无序的数值
    public static void inItNotrder(int[] array) {
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }

    public static void main(String[] args) {
        int[] array = new int[10_0000];
        //测试有序数组
        inItOrder(array);
        testInsertSort(array);
        //测试无序数组
        inItNotrder(array);
        testInsertSort(array);
        System.out.println();

        //测试有序数组
        inItOrder(array);
        testShelltSort(array);
        //测试无序数组
        inItNotrder(array);
        testInsertSort(array);
        System.out.println();

        //测试有序数组
        inItOrder(array);
        testselectSort(array);
        //测试无序数组
        inItNotrder(array);
        testselectSort(array);
        System.out.println();
    }
}
